package com.woniuxy.security.controller;

import com.woniuxy.entity.ResponseResult;
import org.apache.http.client.utils.URIBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.net.URISyntaxException;

@RestController
public class AuthController {
    @Value("{server.port}")
    private String port;

    @PostMapping("security/auth")
    public ResponseResult<?> auth(String jwt, String url) throws URISyntaxException {
        URI uri = new URIBuilder().setScheme("http").setHost("localhost").setPort(Integer.getInteger(port)).setPath(url).build();
        HttpHeaders headers = new HttpHeaders();
        headers.add("Authorization",jwt);
        RestTemplate restTemplate =new RestTemplate();
        return restTemplate.postForObject(uri,new HttpEntity<String>(headers),ResponseResult.class);
    }
}
